package ca.uwo.android.directoryservice;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JSONDataParser {
	static private ArrayList<DirectorySearchData> studentList = new ArrayList<DirectorySearchData>();
	static private ArrayList<DirectorySearchData> facultyList = new ArrayList<DirectorySearchData>();

	static ArrayList<DirectorySearchData> parseStudent(JSONArray array) throws JSONException {
		studentList.clear();
		
		for(int i = 0; i < array.length(); i++) {
			JSONObject object = array.getJSONObject(i);
			StudentData sdata = new StudentData(object);
			
			studentList.add((DirectorySearchData)sdata);
		}

		return studentList;
	}

	static public ArrayList<DirectorySearchData> getStudents() {
		return studentList;		
	}

	static ArrayList<DirectorySearchData> parseFaculty(JSONArray array) throws JSONException {
		facultyList.clear();
		
		for(int i = 0; i < array.length(); i++) {
			JSONObject object = array.getJSONObject(i);
			FacultyData fdata = new FacultyData(object);

			facultyList.add((DirectorySearchData)fdata);
		}

		return facultyList;
	}

	static public ArrayList<DirectorySearchData> getFaculty() {
		return facultyList;		
	}
}